home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows3 / metavi.zip / DISPMETA.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-09  |  6KB  |  214 lines

  1. program DisplayMetafiles;
  2.  
  3. {$R VIEWMETA.RES}
  4.  
  5. uses WinTypes, WinProcs, WObjects,
  6.      Strings, StdDlgs, ViewMeta;
  7.  
  8. const
  9.    id_Viewer = 201;
  10.  
  11.    cm_Open = 101;
  12.    cm_About = 102;
  13.    cm_PreserveAspect = 103;
  14.    cm_DialogExample = 104;
  15.  
  16. type
  17.    PMyChildWindow = ^MyChildWindow;
  18.    MyChildWindow = object(TWindow)
  19.       MetaWnd : PMetafileViewer;
  20.       constructor Init(AParent: PWindowsObject; ATitle: PChar);
  21.       destructor Done; virtual;
  22.       function GetClassName: PChar; virtual;
  23.       procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  24.       procedure WMSize(var Msg: TMessage); virtual wm_First + wm_Size;
  25.       procedure WMMDIActivate(var Msg: TMessage); virtual wm_First + wm_MDIActivate;
  26.       procedure CMPreserveAspect(var Msg: TMessage); virtual cm_First + cm_PreserveAspect;
  27.       procedure SetPreserveAspectCheckMark; virtual;
  28.       procedure IDViewer(var Msg: TMessage); virtual id_First + id_Viewer;
  29.    end;
  30.  
  31.    PMyMDIWindow = ^MyMDIWindow;
  32.    MyMDIWindow = object(TMDIWindow)
  33.       AName:PChar;
  34.       constructor Init(ATitle: PChar; AMenu: HMenu);
  35.       destructor Done; virtual;
  36.       procedure GetWindowClass(var AWndClass: TWndClass); virtual;
  37.       procedure SetupWindow; virtual;
  38.       function InitChild: PWindowsObject; virtual;
  39.       procedure CMOpen(var Msg: TMessage); virtual cm_First + cm_Open;
  40.       procedure CMAbout(var Msg: TMessage); virtual cm_First + cm_About;
  41.       procedure CMDialogExample(var Msg:TMessage); virtual cm_First + cm_DialogExample;
  42.    end;
  43.  
  44.    PMyApplication = ^MyApplication;
  45.    MyApplication = object(TApplication)
  46.       constructor Init(AName: PChar);
  47.       procedure InitMainWindow; virtual;
  48.       destructor Done; virtual;
  49.    end;
  50.  
  51. {**************************************************************}
  52.  
  53.    constructor MyChildWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  54.       begin
  55.          TWindow.Init(AParent, ATitle);
  56.          Attr.Style:= Attr.Style + ws_Child;
  57.          MetaWnd:= New(PMetafileViewer, Init(@Self, id_Viewer,
  58.                           ATitle, cw_UseDefault, cw_UseDefault,
  59.                           cw_UseDefault, cw_UseDefault, True, False));
  60.       end;
  61.  
  62.    destructor MyChildWindow.Done;
  63.       begin
  64.          TWindow.Done;
  65.       end;
  66.  
  67.    function MyChildWindow.GetClassName: PChar;
  68.       begin
  69.          GetClassName:= 'MyChildWindow';
  70.       end;
  71.  
  72.    procedure MyChildWindow.GetWindowClass(var AWndClass: TWndClass);
  73.       begin
  74.          TWindow.GetWindowClass(AWndClass);
  75.          AWndClass.hIcon:= LoadIcon(HInstance, 'METAV_ICON');
  76.       end;
  77.  
  78.    procedure MyChildWindow.WMSize(var Msg: TMessage);
  79.       begin
  80.          TWindow.WMSize(Msg);
  81.          MoveWindow(MetaWnd^.HWindow, 0, 0, Msg.lParamLo, Msg.lParamHi, True);
  82.       end;
  83.  
  84.    procedure MyChildWindow.IDViewer(var Msg: TMessage);
  85.       begin
  86.          if (Msg.lParamHi = mfn_Clicked) then
  87.             begin
  88.                {Metafile Client area was clicked on}
  89.             end
  90.          else if (Msg.lParamHi = mfn_DblClicked) then
  91.             begin
  92.                {Metafile Client area was double clicked on}
  93.             end
  94.          else if (Msg.lParamHi = mfn_Aldus) then
  95.             begin
  96.                {Metafile is an Aldus metafile}
  97.             end
  98.          else if (Msg.lParamHi = mfn_MSoft) then
  99.             begin
  100.                {Metafile is an Microsoft metafile}
  101.             end;
  102.       end;
  103.  
  104.    procedure MyChildWindow.WMMDIActivate(var Msg: TMessage);
  105.       begin
  106.          if (Msg.wParam <> 0) then {Window is being activated}
  107.             begin
  108.                SetPreserveAspectCheckMark;
  109.             end;
  110.       end;
  111.  
  112.    procedure MyChildWindow.CMPreserveAspect(var Msg: TMessage);
  113.       begin
  114.          MetaWnd^.ToggleAspect;
  115.          SetPreserveAspectCheckMark;
  116.       end;
  117.  
  118.    procedure MyChildWindow.SetPreserveAspectCheckMark;
  119.       var
  120.          MenuHandle : HMenu;
  121.          CheckStatus : word;
  122.       begin
  123.          if MetaWnd^.AspectRatioPreserved then
  124.             CheckStatus:= mf_Checked
  125.          else
  126.             CheckStatus:= mf_UnChecked;
  127.  
  128.          MenuHandle:= GetMenu(Application^.MainWindow^.HWindow);
  129.          CheckMenuItem(MenuHandle, cm_PreserveAspect ,CheckStatus);
  130.       end;
  131.  
  132. {**************************************************************}
  133.  
  134.    constructor MyMDIWindow.Init(ATitle: PChar; AMenu: HMenu);
  135.       begin
  136.          TMDIWindow.Init(ATitle, AMenu);
  137.          ChildMenuPos:= 2;
  138.       end;
  139.  
  140.    destructor MyMDIWindow.Done;
  141.       begin
  142.          TMDIWindow.Done;
  143.       end;
  144.  
  145.    procedure MyMDIWindow.GetWindowClass(var AWndClass: TWndClass);
  146.       begin
  147.          TWindow.GetWindowClass(AWndClass);
  148.          AWndClass.hIcon:= LoadIcon(HInstance, 'APGM_ICON');
  149.       end;
  150.  
  151.    procedure MyMDIWindow.SetupWindow;
  152.       begin
  153.         TMDIWindow.SetupWindow;
  154.       end;
  155.  
  156.    function MyMDIWindow.InitChild: PWindowsObject;
  157.       begin
  158.          InitChild:= New(PMyChildWindow, Init(@Self, AName));
  159.       end;
  160.  
  161.    procedure MyMDIWindow.CMOpen(var Msg: TMessage);
  162.       var
  163.          AFile: array[0..100] of char;
  164.       begin
  165.          StrCopy(AFile, '*.WMF');
  166.          if Application^.ExecDialog(New(PFileDialog, Init(@Self,
  167.                PChar(sd_FileOpen), AFile))) = id_OK then
  168.             begin
  169.                AName:= AFile;
  170.                CreateChild;
  171.             end;
  172.          DefWndProc(Msg);
  173.       end;
  174.  
  175.    procedure MyMDIWindow.CMAbout(var Msg: TMessage);
  176.       begin
  177.          Application^.ExecDialog(
  178.             New(PDialog, Init(@Self, 'ABOUT')));
  179.       end;
  180.  
  181.    procedure MyMDIWindow.CMDialogExample(var Msg:TMessage);
  182.       begin
  183.          Application^.ExecDialog(
  184.             New(PDialog, Init(@Self, 'META_DLG')));
  185.       end;
  186.  
  187. {**************************************************************}
  188.  
  189.    constructor MyApplication.Init(AName: PChar);
  190.       begin
  191.          TApplication.Init(AName);
  192.       end;
  193.  
  194.    procedure MyApplication.InitMainWindow;
  195.       begin
  196.          MainWindow:= New(PMyMDIWindow, Init('Metafile Viewer', LoadMenu(HInstance, 'DEFAULT_MENU')));
  197.       end;
  198.  
  199.    destructor MyApplication.Done;
  200.       begin
  201.          TApplication.Done;
  202.       end;
  203.  
  204. {**************************************************************}
  205.  
  206. var
  207.    MyApp : MyApplication;
  208.  
  209. begin
  210.    MyApp.Init('Metafile Viewer');
  211.    MyApp.Run;
  212.    MyApp.Done;
  213. end.
  214.